{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Count Operations to Obtain Zero"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: countOperations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #得到 0 的操作数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个 <strong>非负</strong> 整数 <code>num1</code> 和 <code>num2</code> 。</p>\n",
    "\n",
    "<p>每一步 <strong>操作</strong>&nbsp;中，如果 <code>num1 &gt;= num2</code> ，你必须用 <code>num1</code> 减 <code>num2</code> ；否则，你必须用 <code>num2</code> 减 <code>num1</code> 。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>例如，<code>num1 = 5</code> 且 <code>num2 = 4</code> ，应该用&nbsp;<code>num1</code> 减 <code>num2</code> ，因此，得到 <code>num1 = 1</code> 和 <code>num2 = 4</code> 。然而，如果 <code>num1 = 4</code>且 <code>num2 = 5</code> ，一步操作后，得到 <code>num1 = 4</code> 和 <code>num2 = 1</code> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>返回使 <code>num1 = 0</code> 或 <code>num2 = 0</code> 的 <strong>操作数</strong> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>num1 = 2, num2 = 3\n",
    "<strong>输出：</strong>3\n",
    "<strong>解释：</strong>\n",
    "- 操作 1 ：num1 = 2 ，num2 = 3 。由于 num1 &lt; num2 ，num2 减 num1 得到 num1 = 2 ，num2 = 3 - 2 = 1 。\n",
    "- 操作 2 ：num1 = 2 ，num2 = 1 。由于 num1 &gt; num2 ，num1 减 num2 。\n",
    "- 操作 3 ：num1 = 1 ，num2 = 1 。由于 num1 == num2 ，num1 减 num2 。\n",
    "此时 num1 = 0 ，num2 = 1 。由于 num1 == 0 ，不需要再执行任何操作。\n",
    "所以总操作数是 3 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>num1 = 10, num2 = 10\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>\n",
    "- 操作 1 ：num1 = 10 ，num2 = 10 。由于 num1 == num2 ，num1 减 num2 得到 num1 = 10 - 10 = 0 。\n",
    "此时 num1 = 0 ，num2 = 10 。由于 num1 == 0 ，不需要再执行任何操作。\n",
    "所以总操作数是 1 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>0 &lt;= num1, num2 &lt;= 10<sup>5</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [count-operations-to-obtain-zero](https://leetcode.cn/problems/count-operations-to-obtain-zero/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [count-operations-to-obtain-zero](https://leetcode.cn/problems/count-operations-to-obtain-zero/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['2\\n3', '10\\n10']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        if (num1==0) | (num2==0): return 0\n",
    "        control = 0\n",
    "        while (num1!=0) & (num2!=0):\n",
    "            if num1>=num2:\n",
    "             num1 = (num1 - num2)\n",
    "             control += 1\n",
    "            else:\n",
    "             num2 = (num2 - num1)\n",
    "             control += 1\n",
    "        return control"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "        # while num1 or num2 != 0:\n",
    "            if num1 > num2:\n",
    "                num1 -= num2\n",
    "            elif num1 == num2:\n",
    "                num1 = num2 = 0\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        a=0\n",
    "        num1,num2=max(num1,num2),min(num1,num2)\n",
    "        while num2!=0:\n",
    "            a+=num1//num2\n",
    "            num1,num2=num2,num1%num2\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1 and num2:\n",
    "            ans += num1 // num2\n",
    "            num1 %= num2\n",
    "            num1, num2 = num2, num1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        cnt, min_num = 0, num1  if num1 < num2 else num2\n",
    "        while min_num > 0:\n",
    "            if num1 < num2:\n",
    "                num1, num2 = num2, num1\n",
    "            # 出现倍数关系需要减倍数次\n",
    "            ops, num1 = divmod(num1, num2)    \n",
    "            cnt += ops\n",
    "            min_num = num1  if num1 < num2 else num2\n",
    "        return cnt\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        if (num1==0) | (num2==0): return 0\n",
    "        control = 0\n",
    "        #---------------------------#\n",
    "        # 找到控制变量的边界范围\n",
    "        #---------------------------#\n",
    "        while (num1!=0) & (num2!=0):\n",
    "            if num1>=num2:\n",
    "             num1 = (num1 - num2)\n",
    "            \n",
    "            else:\n",
    "             num2 = (num2 - num1)\n",
    "            control += 1\n",
    "        return control"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "'''\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2 :\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            res += 1\n",
    "        return res\n",
    "'''\n",
    "'''\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1:\n",
    "            ans += num2 // num1\n",
    "            num1, num2 = num2 % num1, num1\n",
    "        return ans\n",
    "'''\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1 and num2:\n",
    "            if num1 >= num2 :\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res=0\n",
    "        while num1!=0 and num2!=0:\n",
    "            if num1>=num2:\n",
    "                num1-=num2\n",
    "            else:\n",
    "                num2-=num1\n",
    "            res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num2 != 0 and num1 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1 = num1 - num2\n",
    "            elif num2 >= num1:\n",
    "                num2 = num2 - num1\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "      res = 0\n",
    "      while num1 != 0 and num2 != 0:\n",
    "        if num1 >= num2:\n",
    "          num1 -= num2\n",
    "        else:\n",
    "          num2 -= num1\n",
    "        res += 1\n",
    "      return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            ans += 1\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1 and num2:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            count += 1\n",
    "        return count "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        n = 0\n",
    "        num1, num2 = max(num1, num2), min(num1, num2)\n",
    "        while num2 != 0:\n",
    "            num1, num2 = max(num1-num2, num2), min(num1- num2, num2)\n",
    "            n += 1\n",
    "        return n "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count=0\n",
    "        while num1!=0 and num2!=0:\n",
    "            if num1>=num2:\n",
    "                num1=num1-num2\n",
    "                count+=1\n",
    "            else:\n",
    "                num2=num2-num1\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        cnt = 0\n",
    "        while num1 and num2:\n",
    "            cnt += 1\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        q=0\n",
    "        while num1>0 and num2>0:      \n",
    "            if num1>=num2:\n",
    "                num1,num2=num1-num2,num2\n",
    "            else:\n",
    "                num1,num2=num1,num2-num1\n",
    "            q+=1\n",
    "        return q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        cnt=0\n",
    "        if num1 ==0 or num2 ==0:\n",
    "            return 0\n",
    "        while True:\n",
    "            cnt+=1\n",
    "            \n",
    "            if num1>=num2:\n",
    "                num1=num1-num2 \n",
    "            elif num2>num1:\n",
    "                num2=num2-num1 \n",
    "\n",
    "            if num2==0 or num1==0:\n",
    "                break\n",
    "\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        cnt = 0\n",
    "        min_num = num1 if num1 < num2 else num2\n",
    "        while min_num > 0:\n",
    "            if num1 < num2:\n",
    "                num1, num2 = num2, num1\n",
    "            # 出现倍数关系需要减倍数次\n",
    "            ops, num1 = num1 // num2, num1 % num2\n",
    "            cnt += ops\n",
    "            min_num = num1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        counter = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            counter += 1\n",
    "\n",
    "        return counter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "                count += 1\n",
    "            else:\n",
    "                num2 -= num1\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1, num2):\n",
    "        result = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            result += 1\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count=0\n",
    "        while num1 and num2:\n",
    "            if num1>=num2:\n",
    "                num1-=num2\n",
    "            else:\n",
    "                num2-=num1\n",
    "            count+=1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1 and num2:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1 * num2:\n",
    "            ans += num1 // num2\n",
    "            num1 %= num2\n",
    "            num1, num2 = num2, num1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1!=0 and num2!=0:\n",
    "            temp = min(num1,num2)\n",
    "            num1 = abs(num1-num2)\n",
    "            num2 = temp\n",
    "            res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1 * num2 != 0:\n",
    "            if num1>num2:\n",
    "                res += num1 // num2\n",
    "                num1 = num1 % num2\n",
    "            else:\n",
    "                res += num2 // num1\n",
    "                num2 = num2 % num1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1 and num2:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        cnt =0\n",
    "        while num1 !=0 and num2 != 0:\n",
    "            num1,num2= max(num1,num2),min(num1,num2)\n",
    "            num1,num2= num2,num1-num2\n",
    "            cnt +=1\n",
    "        return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        i = 0\n",
    "        while num1 !=0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1= num1 - num2\n",
    "                i = i + 1\n",
    "                continue\n",
    "            num2 = num2 - num1\n",
    "            i = i + 1\n",
    "        return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        cnt = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            cnt += 1\n",
    "        return cnt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        c = 0\n",
    "        while num1 and num2:\n",
    "            num1,num2 = max(num1,num2),min(num1,num2)\n",
    "            num1 -= num2\n",
    "            c +=1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        if num1==0 or num2==0:\n",
    "            return 0\n",
    "        count=0\n",
    "        while True:\n",
    "            df=abs(num1-num2)\n",
    "            num2=min(num1,num2)\n",
    "            num1=df\n",
    "            count+=1\n",
    "            if df==0:\n",
    "                break\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            count += 1\n",
    "        return count\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res=0\n",
    "        i=min(num1, num2)\n",
    "        while i>0:\n",
    "            if num1>=num2:\n",
    "                num1-=num2\n",
    "            else:\n",
    "                num2-=num1\n",
    "            res+=1\n",
    "            i=min(num1,num2)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, nums1: int, nums2: int) -> int:\n",
    "        ans = 0\n",
    "        while nums1 > 0 and nums2 > 0:\n",
    "            if nums1 >= nums2:\n",
    "                ans += nums1//nums2\n",
    "                nums1 = nums1 - (nums1//nums2) * nums2\n",
    "            else:\n",
    "                ans += nums2//nums1\n",
    "                nums2 = nums2 - (nums2//nums1) * nums1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        total = 0\n",
    "\n",
    "        while min(num1,num2) > 0:\n",
    "            if num1 >= num2:\n",
    "                num1 = num1-num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            total += 1\n",
    "\n",
    "        return total\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "                ans += 1\n",
    "            else:\n",
    "                num2 -= num1\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        # cnt = 0\n",
    "        # while num1 and num2:\n",
    "        #     if num1 >= num2:\n",
    "        #         num1 -= num2\n",
    "        #     else:\n",
    "        #         num2 -= num1\n",
    "        #     cnt += 1\n",
    "        # return cnt\n",
    "\n",
    "        # 辗转相除\n",
    "        res = 0\n",
    "        while num1 and num2:\n",
    "            # num1变成比num2小需要的操作数\n",
    "            res += num1//num2\n",
    "            # num1的新数值就是取模后的值\n",
    "            num1 %= num2\n",
    "            # 再交换相除\n",
    "            num1,num2 = num2,num1\n",
    "        return res\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        cnt = 0\n",
    "        while num1 and num2:\n",
    "            if num1 >= num2:\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        s=0\n",
    "        while(num1!=0 and num2!=0):\n",
    "            if num1>=num2:\n",
    "                num1=num1-num2\n",
    "\n",
    "                s+=1\n",
    "            else:\n",
    "                num2=num2-num1\n",
    "\n",
    "                s+=1\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1 and num2:\n",
    "            res += num1 // num2\n",
    "            num1 %= num2\n",
    "            num1, num2 = num2, num1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        if num1 == 0 or num1 == 0:\n",
    "            return 0\n",
    "        ans = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 > num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ret = 0\n",
    "        while 0 not in (num1, num2):\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            ret += 1\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2 :\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            res += 1\n",
    "        return res\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        oper=0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1>=num2:\n",
    "                num1-=num2\n",
    "            else:\n",
    "                num2-=num1\n",
    "            oper+=1\n",
    "        return oper\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ret = 0\n",
    "        while 0 not in (num1, num2):\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            ret += 1\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count = 0\n",
    "        while num1 and num2:\n",
    "            # print(\"num1: %s, nums: %s\" % (num1, num2))\n",
    "            if num1 >= num2:\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            count += 1\n",
    "        return count\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        cnt = 0\n",
    "        while num1 and num2:\n",
    "            cnt += num1//num2\n",
    "            num1 %= num2\n",
    "            num1,num2 = num2, num1\n",
    "        return cnt\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1 and num2:\n",
    "            if num1 > num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "'''\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2 :\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            res += 1\n",
    "        return res\n",
    "'''\n",
    "'''\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1:\n",
    "            ans += num2 // num1\n",
    "            num1, num2 = num2 % num1, num1\n",
    "        return ans\n",
    "'''\n",
    "'''\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1 and num2:\n",
    "            if num1 >= num2 :\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            res += 1\n",
    "        return res\n",
    "'''\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        if num1==0 or num2==0:\n",
    "            return 0\n",
    "        if num1 % num2 == 0 :\n",
    "            return num1//num2\n",
    "        if num2%num1==0  :\n",
    "            return num2//num1\n",
    "        res = 0\n",
    "        while num1 and num2:\n",
    "            if num1 >= num2 :\n",
    "                num1 = num1 - num2\n",
    "            else:\n",
    "                num2 = num2 - num1\n",
    "            res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0   # 相减操作的总次数\n",
    "        while num1 and num2:\n",
    "            # 每一步辗转相除操作\n",
    "            res += num1 // num2\n",
    "            num1 %= num2\n",
    "            num1, num2 = num2, num1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        if (num1==0) | (num2==0): return 0\n",
    "        control = 0\n",
    "        #---------------------------#\n",
    "        # 找到控制变量的边界范围\n",
    "        #---------------------------#\n",
    "        while (num1!=0) & (num2!=0):\n",
    "            if num1>=num2:\n",
    "             num1 = (num1 - num2)\n",
    "            \n",
    "            else:\n",
    "             num2 = (num2 - num1)\n",
    "            control += 1\n",
    "        return control"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        c = 0\n",
    "        while num1 and num2:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:num2 -= num1\n",
    "            c +=1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        c=0\n",
    "        while num1!=0 and num2!=0:\n",
    "            if num1<=num2:\n",
    "                num2=num2-num1\n",
    "                c+=1\n",
    "            else:\n",
    "                num1=num1-num2\n",
    "                c+=1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans=0\n",
    "        while True:\n",
    "            if num1==0 or num2==0:\n",
    "                return ans\n",
    "            \n",
    "            if num1>=num2:\n",
    "                num1-=num2\n",
    "            else:\n",
    "                num2-=num1\n",
    "            ans+=1\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        tot = 0\n",
    "        while num1 > 0 and num2 > 0:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2 \n",
    "            else:\n",
    "                num2 -= num1 \n",
    "            tot += 1\n",
    "        return tot \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1 and num2:\n",
    "            if num1 >= num2:\n",
    "                ans += num1 // num2\n",
    "                num1 %= num2\n",
    "            else:\n",
    "                ans += num2 // num1\n",
    "                num2 %= num1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        num1, num2 = min(num1, num2), max(num1, num2)\n",
    "        if num1 == 0:\n",
    "            return 0\n",
    "        \n",
    "        return self.countOperations(num1, num2 % num1) + num2 // num1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            t = abs(num1 - num2)\n",
    "            num1, num2 = min(num1, num2), t\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count = 0\n",
    "        while(num1>0 and num2>0):\n",
    "            if num1 >= num2:\n",
    "                num1,num2 = num1-num2, num2\n",
    "            else:        \n",
    "                num1,num2 = num1, num2 - num1\n",
    "            count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count = 0\n",
    "        while num1 and num2:\n",
    "            count += num1 // num2\n",
    "            num1 %= num2\n",
    "            num1, num2 = num2, num1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        if num1 == 0 or num2 == 0:\n",
    "            return 0\n",
    "        c = 1\n",
    "        while num1 != num2:\n",
    "            num1, num2 = max(num1, num2), min(num1, num2)\n",
    "            num1 = num1-num2 \n",
    "            c+=1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans=0\n",
    "        while num1>0 and num2>0:\n",
    "            if num1>=num2:\n",
    "                ans+=num1//num2\n",
    "                num1=num1%num2\n",
    "                \n",
    "            else:\n",
    "                ans+=num2//num1\n",
    "                num2=num2%num1\n",
    "        \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1 * num2 != 0:\n",
    "            if num1>num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        c=0\n",
    "        while (num1!=0 and num2!=0):\n",
    "            if num1>num2:\n",
    "                num1-=num2\n",
    "            else:\n",
    "                num2-=num1\n",
    "            c+=1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ans=0\n",
    "        while num1!=0 and num2!=0:\n",
    "            if num1<num2:\n",
    "                num1,num2=num2,num1\n",
    "            ans+=num1//num2\n",
    "            num1%=num2\n",
    "            num1,num2=num2,num1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        res = 0\n",
    "        while num1 and num2:\n",
    "            res += num1//num2\n",
    "            num1 %= num2\n",
    "            num1,num2 = num2,num1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        n1, n2 = num1, num2\n",
    "        cnt = 0\n",
    "        while n1 and n2:\n",
    "            if n1 >= n2:\n",
    "                cnt += n1//n2\n",
    "                n1 -= n1//n2 * n2\n",
    "            else:\n",
    "                cnt += n2//n1\n",
    "                n2 -= n2//n1 * n1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "      count = 0\n",
    "      while num1 != 0 and num2 != 0:\n",
    "          if num1 >= num2:\n",
    "              num1 -= num2\n",
    "          else:\n",
    "              num2 -= num1\n",
    "          count += 1\n",
    "      return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        count = 0\n",
    "        while num1 != 0 and num2 != 0:\n",
    "            if num1 >= num2:\n",
    "                num1-=num2\n",
    "                count+=1\n",
    "            else:\n",
    "                num2-=num1\n",
    "                count+=1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        if num1 == 0 or num2 == 0:\n",
    "            return 0\n",
    "        ans = 0\n",
    "        while num1 > 0 and num2 > 0:\n",
    "            if num2 > num1:\n",
    "                num1, num2 = num2, num1\n",
    "            x, y = divmod(num1, num2)\n",
    "            ans += x\n",
    "            num1, num2 = num2, y\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOperations(self, num1: int, num2: int) -> int:\n",
    "        ret = 0\n",
    "        while num1 and num2:\n",
    "            if num1 >= num2:\n",
    "                num1 -= num2\n",
    "            else:\n",
    "                num2 -= num1\n",
    "            ret += 1\n",
    "        return ret"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
